package com.qianyu.project.mapper.provider.mfy;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qianyu.project.entity.ProjectInfo;
import org.apache.ibatis.jdbc.SQL;
import org.springframework.util.ObjectUtils;

import java.util.Map;

/**
 * @Author mfy
 * @desc
 */
public class ProjectInfoProvider {

    public String MfyCreatedList(IPage<ProjectInfo> page, Map<String, String> params){
        return new SQL(){
            {
//                select * from project_info pi,project_type pt where pt.type_id=pi.project_type
                    SELECT("pi.*,pt.type_name MfyCreatedTypeName,ii.name as createPerson");
                    FROM("project_info pi,project_type pt,identify_info ii");
                    WHERE("pt.type_id=pi.project_type");
                    WHERE("pi.creator=ii.id");
                    if(!ObjectUtils.isEmpty(params.get("projectType"))){
                        WHERE("pi.project_type = '"+params.get("projectType")+"'");
                    }
                    if(!ObjectUtils.isEmpty(params.get("id"))){
                        WHERE("pi.id like '%"+params.get("id")+"%'");
                    }
                    if(!ObjectUtils.isEmpty(params.get("projectName"))){
                        WHERE("pi.project_name like '%"+params.get("projectName")+"%'");
                    }
                    if(!ObjectUtils.isEmpty(params.get("approveStatus"))){
                        WHERE("pi.approve_status=#{params.approveStatus}");
                    }
            }
        }.toString();
    }

    public String WyhCreatedList(IPage<ProjectInfo> page, Map<String, String> params){
        return new SQL(){
            {
//                select * from project_info pi,project_type pt where pt.type_id=pi.project_type
                SELECT("pi.*,pt.type_name MfyCreatedTypeName,ii.name as createPerson," +
                        " ls.contract_name,ls.contract_amount,ls.deposit_amount,pp.provider_name," +
                        " ls.i con_id,ls.pro_id");
                FROM("project_info pi,project_type pt,identify_info ii,labor_subcontract ls," +
                        " provider_info pp");
                WHERE("pt.type_id=pi.project_type");
                WHERE("pi.creator=ii.id");
                WHERE("pi.id=ls.p_id");
                WHERE("ls.pro_id=pp.id");
                if(!ObjectUtils.isEmpty(params.get("projectType"))){
                    WHERE("pi.project_type = '"+params.get("projectType")+"'");
                }
                if(!ObjectUtils.isEmpty(params.get("id"))){
                    WHERE("pi.id like '%"+params.get("id")+"%'");
                }
                if(!ObjectUtils.isEmpty(params.get("projectName"))){
                    WHERE("pi.project_name like '%"+params.get("projectName")+"%'");
                }
                if(!ObjectUtils.isEmpty(params.get("approveStatus"))){
                    WHERE("pi.approve_status=#{params.approveStatus}");
                }
            }
        }.toString();
    }
}
